【Linux】Busybox make menuconfig 报错:Unable to find the ncurses libraries
省流:目前的 busybox 版本是 1.36.1,而我使用的 gcc 版本是 14.1.1 20240522 (GCC),在 /home/.../busybox-1.36.1/scripts/kconfig/lxdialog/check-lxdialog.sh
脚本中将第 50 行的 main() {}
改为 int main() {}
即可。
问题描述
今天在配置 busybox 的时候,出现如下错误:
HOSTCC scripts/kconfig/lxdialog/util.o
HOSTCC scripts/kconfig/lxdialog/yesno.o
HOSTLD scripts/kconfig/lxdialog/lxdialog
*** Unable to find the ncurses libraries or the
*** required header files.
*** 'make menuconfig' requires the ncurses libraries.
***
*** Install ncurses (ncurses-devel) and try again.
***
make[2]: *** [/.../busybox-1.36.1/scripts/kconfig/lxdialog/Makefile:15: scripts/kconfig/lxdialog/dochecklxdialog] Error 1
make[1]: *** [/.../busybox-1.36.1/scripts/kconfig/Makefile:14: menuconfig] Error 2
make: *** [Makefile:444: menuconfig] Error 2
解决办法
这个错误其实并不完全是提示缺少 ncurses 库,我们只需要通过 ls 命令查看一下 ncurses 库是否存在即可。
ls /usr/include/ | grep ncurses
只要能看到 ncurses.h 就说明其实是已经安装了 ncurses 库了,但是为什么提示缺少 ncurses 库呢? 因为 check-lxdialog.sh 脚本中的 check 实现是这样的:
# Check if we can link to ncurses
check() {
$cc -x c - -o $tmp 2>/dev/null <<'EOF'
#include CURSES_LOC
main() {}
EOF
if [ $? != 0 ]; then
echo " *** Unable to find the ncurses libraries or the" 1>&2
echo " *** required header files." 1>&2
echo " *** 'make menuconfig' requires the ncurses libraries." 1>&2
echo " *** " 1>&2
echo " *** Install ncurses (ncurses-devel) and try again." 1>&2
echo " *** " 1>&2
exit 1
fi
}
这个脚本中,它通过编译一个简单的 C 程序来检查 ncurses 库是否可用。但是这个程序并不只会在 ncurses.h
头文件找不到的时候报错,把 2>/dev/null
去掉就会发现被隐藏的报错其实是 <stdin>:2:1: error: return type defaults to ‘int’ [-Wimplicit-int]
,这个错误是由于 gcc14 版本 的检查更严格,要求函数的返回值类型不能省略。解决办法就是将 main() {}
改为 int main() {}
,或者把编译器更换成 gcc13 也可以。